package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.Fitting2;
import com.miyake.dsp.osa.lab.FittingSetting2;
import com.miyake.dsp.osa.lab.LabUiAnnotation;

@LabUiAnnotation(caption="Fitting")
public class FittingWrapper extends Calculator {
	public static final String INPUT_X = "Input X";
	public static final String INPUT_Y = "Input Y";
	public static final String INPUT_INTERPOLATION = "Interpol. X";
	public static final String OUTPUT_Y = "Interpol. Y";
	
	private FittingSetting2 setting;

	public FittingWrapper(FittingSetting2 setting) {
		this.setting = setting;
		initInput(INPUT_X);
		initInput(INPUT_Y);
		initInput(INPUT_INTERPOLATION);
		initOutput(OUTPUT_Y);
	}
	
	@Override
	public synchronized void process() {
		Fitting2 fitting = new Fitting2(this.setting.getFormula());
		fitting.setOriginalData(
				this.getInput(INPUT_X).getRealPart(), 
				this.getInput(INPUT_Y).getRealPart());
		setOutput(OUTPUT_Y, 
				new ComplexArray(fitting.getInterpolated(this.getInput(INPUT_INTERPOLATION).getRealPart())));

	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
